from django.http import Http404, HttpResponse
import datetime

def hello(request):
    return HttpResponse("Hello world!")

def current_date_time(request):
    now = datetime.datetime.now()
    html = "<html>" \
        "<body>"    \
            "It is now %s."  \
        "</body>"   \
    "</html>" % now
    return HttpResponse(html)

def current_date_time_plus(request, offset_hour):
    time = 0
    try:
        time = datetime.datetime.now() + datetime.timedelta(hours=int(offset_hour))
    except ValueError:
        raise Http404
    except OverflowError:
        return HttpResponse("OverflowError")

    html = "<html>" \
        "<body>"    \
            "%s hour from now, it will be %s."  \
        "</body>"   \
    "</html>" % (offset_hour, time)
    return HttpResponse(html)

def current_date_time_plus_template(request, offset_hour):
    from django.template import Template, Context
    from django.template.loader import get_template

    time = 0
    try:
        time = datetime.datetime.now() + datetime.timedelta(hours=int(offset_hour))
    except ValueError:
        raise Http404
    except OverflowError:
        return HttpResponse("OverflowError")

    t = get_template('urrent_date_time_plus_template.html')
    html = t.render(Context({"offset_hour":offset_hour, "time":time}))
    return HttpResponse(html)
